
CC      = gcc
CPP     = g++
#-Wmaybe-uninitialized
CFLAGS += -O1 -g -Wall #-fsanitize=address -fno-omit-frame-pointer   #--no-whole-archive -fsanitize=address -fno-omit-frame-pointer  
CCFLAGS += -O1 -g -Wall -std=c++11
DFLAGS = -DLV_CONF_INCLUDE_SIMPLE -DLV_LVGL_H_INCLUDE_SIMPLE -DUSE_EVDEV=1 -DUSE_FBDEV=1 -DUSE_SDL=1  #-DHAVE_CONFIG_H=1  #宏定义
LDFLAGS =  -lstdc++
LIBRARIES =  -lpthread  -lrt -lSDL2              #链接库-lasan
INC_DIR = -I./lvgl -I./common/log -I./common/msg_com  -I./common/ui_basic -I./mid -I./app/config -I./app/ui_app -I./port #头文件路径	
INC_DIR += -I./app/ui_app/ui_com
INC_DIR += -I./app/ui_app/ui_other
INC_DIR += -I./app/ui_app/ui_asserts
INC_DIR += -I./common/stack

BIN = easyui             #生成的固件名
MAINSRC = main.c         #主源文件

LVGL_DIR := $(shell pwd)
LVGL_DIR_NAME := lvgl
include ./lvgl/lvgl.mk

#查找所有源文件
ROOT_PATH = $(shell pwd)
$(info $(ROOT_PATH) )
DIRS := $(ROOT_PATH)/common/log
DIRS += $(ROOT_PATH)/common/msg_com
DIRS += $(ROOT_PATH)/common/ui_basic
DIRS += $(ROOT_PATH)/common/stack
DIRS += $(ROOT_PATH)/mid
DIRS += $(ROOT_PATH)/port
DIRS += $(ROOT_PATH)/app/ui_app
DIRS += $(ROOT_PATH)/app/config
DIRS += $(ROOT_PATH)/app/ui_app/ui_com
DIRS += $(ROOT_PATH)/app/ui_app/ui_other
DIRS += $(ROOT_PATH)/app/ui_app/ui_asserts

VPATH += :$(ROOT_PATH)/common/stack
VPATH += :$(ROOT_PATH)/common/log
VPATH += :$(ROOT_PATH)/common/msg_com
VPATH += :$(ROOT_PATH)/common/ui_basic
VPATH += :$(ROOT_PATH)/mid
VPATH += :$(ROOT_PATH)/port
VPATH += :$(ROOT_PATH)/app/ui_app
VPATH += :$(ROOT_PATH)/app/ui_app/ui_com
VPATH += :$(ROOT_PATH)/app/ui_app/ui_other
VPATH += :$(ROOT_PATH)/app/config
VPATH += :$(ROOT_PATH)/app/ui_app/ui_asserts
#DIRS += ${VPATH}

#$(info $(DIRS) )
#$(notdir 

#声明查找路径
vpath %.c $(VPATH)

SRCS := $(notdir $(basename $(foreach dir,$(DIRS),$(wildcard $(dir)/*.cpp))))#其他源文件
SRCS += $(notdir $(basename $(foreach dir,$(DIRS),$(wildcard $(dir)/*.c))))
LVGL_SRCS += $(notdir $(basename $(CSRCS)))
SRCS += $(LVGL_SRCS)

#build路径
BUILD_DIR = ./build/

#目标文件
$(shell mkdir -p $(BUILD_DIR))
OBJEXT ?= .o   #目标文件类型
SUB_OBJ = $(addprefix $(BUILD_DIR), $(addsuffix .o,$(SRCS)))
MAINOBJ = $(addprefix $(BUILD_DIR), $(MAINSRC:.c=$(OBJEXT)))



#make all时执行后面所有的
all: default


#make自动规划将所有源文件编译成目标文件
$(BUILD_DIR)%.o: %.cpp
	$(CPP)  $(CCFLAGS) $(DFLAGS) $(INC_DIR) -c $< -o $@

$(BUILD_DIR)%.o: %.c
	$(CC)   $(CFLAGS) $(DFLAGS) $(INC_DIR) -c $< -o $@

#make 执行此处 make不加参数时执行此处
default:$(SUB_OBJ) $(MAINOBJ)
	$(CC) -o $(BIN) $(LDFLAGS) $(MAINOBJ) $(SUB_OBJ) $(LIBRARIES) 

clean: 
	rm -f $(BIN) $(SUB_OBJ) $(MAINOBJ)
